var http = require('http');
var url = require('url');
var util = require('util');
var sha1 = require('sha1');
var querystring = require('querystring');
var querystring = require('querystring');
var message = require('../message/message');

var route = function (req, res){
	console.log("---==========-------------ee------");
	res.writeHeader(200, {
		"Content-type": "text/html;charset=utf8"
	})
	var urlParse = url.parse(req.url, true);
	var query = urlParse.query;
	var pathname = urlParse.pathname;
	var postBody = '';
	req.on('data', function(chunk) {
		postBody += chunk;
	});
	req.on('end', function() {
		postBody = querystring.parse(postBody);
		console.log("路由为：" + pathname)
		switch (pathname) {
		    case "/":	// 消息接口调试
				message(req, res, postBody);
				break;
		    default:
				var obj = {
					pathname: pathname,
					query: query,
					queryBody: post,
					doc: "你的url是什么呢？看看了。。。"
				}
				var log = util.inspect(obj);
				console.log(log);
				res.end(log)
		}
	});
}

module.exports = route;
